package com.star.banner.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.star.banner.entity.BannerView;
import com.star.banner.mapper.BannerViewMapper;
import com.star.banner.service.BannerViewService;
import org.springframework.stereotype.Service;

/**
 * banner浏览，区分用户 服务实现类
 *
 * @author lty
 */
@Service
public class BannerViewServiceImpl extends ServiceImpl<BannerViewMapper, BannerView> implements BannerViewService {

    @Override
    public void save(Long bannerId, Long userId) {
        LambdaQueryWrapper<BannerView> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(BannerView::getUserId, userId);
        BannerView bannerView = this.getBaseMapper().selectOne(queryWrapper);
        //重复用户不新增
        if (ObjectUtil.isEmpty(bannerView)) {
            BannerView saveBannerView = new BannerView();
            saveBannerView
                    .setBannerId(bannerId)
                    .setUserId(userId);
            this.save(saveBannerView);
        }
    }
}
